package com.client.handler;

import com.alibaba.fastjson.JSON;
import com.entity.AppInfo;
import com.entity.MsgData;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.SimpleChannelInboundHandler;
import org.springframework.stereotype.Component;

import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.concurrent.TimeUnit;

/**
 * @author tangj
 * @date 2018/5/6 22:59
 */
@Component
public class ClientHandler extends SimpleChannelInboundHandler<MsgData>{

    @Override
    public void channelRead0(ChannelHandlerContext ctx, MsgData msg) throws Exception {
        System.out.println("客户端收到消息:" + JSON.toJSONString(msg));
//        switch (msg.getType()) {
//            case INIT:
//                init(msg.getAppInfo());
//                break;
//            case UPDATE:
//                update(msg.getAppInfo());
//                break;
//            default:
//        }
    }

    private void update(AppInfo appInfo) {

    }

    private void init(AppInfo appInfo) {

    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }

}
